package com.bbcare.sso.client;

import java.io.Serializable;
import org.json.JSONArray;
import org.json.JSONObject;

/**
 * 账号
 * 1、在线医疗服务平台账号体系与BBcare平台账号体系相互独立
 * 2、在OMS平台添加的账号都必须通过消息队列向BBcare平台发送新医生账号注册广播
 * @author lechen
 */
public class Account implements Serializable{

	private static final long serialVersionUID = 1L;
	
	private String id;
	
	//账号
	private String username;
	
	//昵称
	private String alias;
	
	//账号类型
	private int type;
	
	//关联类型ID
	private String relationId;

	//当前登录用户的SessionID
	private String sessionID;
	
	//所属租户
	private Tenant tenant;

	private String refTenantId;

	public String getRefTenantId() {
		return refTenantId;
	}

	public void setRefTenantId(String refTenantId) {
		this.refTenantId = refTenantId;
	}
	
	public Account(JSONObject data){
		this.id 		= data.getString("id");
		this.username 	= data.getString("username");
		this.alias		= data.getString("alias");
		this.type 		= data.getInt("type");
		this.relationId = data.getString("relationId");
		this.sessionID 	= data.getString("sessionID");
		if(data.has("refTenantId")){
			this.refTenantId = data.getString("refTenantId");;
		}
		JSONArray array = (JSONArray) data.get("apps");
		for(int i=0;i<array.length();i++){
			JSONObject json = (JSONObject) array.get(i);
			if(json.getInt("status")==1){
				this.tenant = new Tenant(json);
			}
		}
	}
	
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getAlias() {
		return alias;
	}

	public void setAlias(String alias) {
		this.alias = alias;
	}

	public String getSessionID() {
		return sessionID;
	}

	public void setSessionID(String sessionID) {
		this.sessionID = sessionID;
	}

	public Tenant getTenant() {
		return tenant;
	}

	public void setTenant(Tenant tenant) {
		this.tenant = tenant;
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

	public String getRelationId() {
		return relationId;
	}

	public void setRelationId(String relationId) {
		this.relationId = relationId;
	}

}
